// Copyright (c) 2009 Hypirinha contributers
// This program is made available under the terms of the MIT License.
package org.hypirinha.html;

import org.junit.runner.JUnitCore;

import java.io.File;
import java.io.FilenameFilter;
import java.util.List;
import java.util.ArrayList;

public class TestRunner {

    public static void main(String[] args) throws ClassNotFoundException {
        String resourcePath = TestRunner.class.getPackage().getName().replace('.', '/');

        String directory = TestRunner.class.getResource("/" + resourcePath).getFile();

        List<File> classFiles = DirectoryUtils.recursiveList(new File(directory), new FilenameFilter() {
            public boolean accept(File directory, String name) {
                return name.endsWith("Test.class");
            }
        });

        List<String> classes = new ArrayList<String>();
        for (File classFile : classFiles) {
            String extendedClassName = classFile.getPath().replaceAll("/", ".").replaceAll(".class", "");
            classes.add(extendedClassName.substring(extendedClassName.indexOf(TestRunner.class.getPackage().getName())));
        }

        JUnitCore.main(classes.toArray(new String[classes.size()]));
    }

}
